<?php include_once("header.html")?>

<div id="wrap">  <br />
	<?php include_once("home_left.html")?>
    <div class="admincontent">
		<?php include_once("home_assignmenttop.html")?>

<script src="<?php echo $www_site_url?>/public/js/common.js" type="text/javascript"></script>
<script src="<?php echo $www_site_url?>/public/js/vote.js" type="text/javascript"></script>
<script>

function checkform(form){

	document.getElementById('is_saved').value=2;
	var g=function(n){
		return form.getElementsByTagName(n);
	};
	var va=function(e){
		if(e.name) return encodeURIComponent(e.value);
	};
	var check=function(r){
		for(var i=0;i<r.length;i++){
			if(r[i].checked) return true;
		}
		return false;
	}
	var result = true;

	var input = g('input');
	for(var i=0;i<input.length;i++){
		var v = va(input[i]);
		if(input[i].type=='text' || input[i].type=='hidden'){
			if( v==''){
				input[i].parentNode.style.border='1px solid red';
				result=false;
			}else{
				input[i].parentNode.style.border='';
			}
		}
		if(input[i].type=='radio'){
			if(check(form.elements[input[i].name])){
				input[i].parentNode.style.border='';
			}else{
				input[i].parentNode.style.border='1px solid red';
				result=false;
			}
		}
	}

	var textarea = g('textarea');
	for(var i=0;i<textarea.length;i++){
		var v=va(textarea[i]);
		if(textarea[i].name.indexOf("rq_comment_")!=-1) continue;
		if(v==''){
			textarea[i].style.border='1px solid red';
			result=false;
		}else{
			textarea[i].style.border='';
		}
	}
	if(!result) alert("<?php echo lang("fiinish_redmark_question")?>");
	if(result && confirm("<?php echo lang("submit_alert");?>")){
		return result;
	}else{
		return false;
	}
}

function checktable(table){

	var g=function(n){
		return table.getElementsByTagName(n);
	};
	var va=function(e){
		if(e.name) return encodeURIComponent(e.value);
	};
	var check=function(r){
		var redio = document.getElementsByName(r);
		for(var i=0;i<redio.length;i++){
			if(redio[i].checked) return true;
		}
		return false;
	}
	var result = true;

	var input = g('input');
	for(var i=0;i<input.length;i++){
		var v = va(input[i]);
		if(input[i].type=='text' || input[i].type=='hidden'){
			if( v==''){
				input[i].parentNode.style.border='1px solid red';
				result=false;
			}else{
				input[i].parentNode.style.border='';
			}
		}
		if(input[i].type=='radio'){
			if(check(input[i].name)){
				input[i].parentNode.style.border='';
			}else{
				input[i].parentNode.style.border='1px solid red';
				result=false;
			}
		}
	}

	var textarea = g('textarea');
	for(var i=0;i<textarea.length;i++){
		var v=va(textarea[i]);
		if(textarea[i].name.indexOf("rq_comment_")!=-1) continue;
		if(v==''){
			textarea[i].style.border='1px solid red';
			result=false;
		}else{
			textarea[i].style.border='';
		}
	}
	if(!result) alert("<?php echo lang("fiinish_redmark_question")?>");
	if(result && confirm("<?php echo lang("submit_alert");?>")){
		return result;
	}else{
		return false;
	}
}

</script>

	<?php if($is_view && $assignmentinfo['a_quiz_pass']>0){
		if($is_submitted==0 || $is_submitted==2){

			if($is_submitted==2){
				echo ' <p>&nbsp;</p><div align="center">'.lang("approval_notpass")."</div>";
			}
		if(isset($report_questions) && is_array($report_questions)){?>
			<br /><br />
				 <br />
		    <p><?php echo lang("grade_info")?>：</p>
			<table width="100%" border="0" cellpadding="0" cellspacing="1" class="missionReport" class="clear">
			<?php if($mark_type == 10){?>
          <tr>
            <td class="title"><?php echo lang("level_0")?></td>
            <td class="title"><?php echo lang("level_8")?></td>
            <td class="title"><?php echo lang("level_1")?></td>
            <td class="title"><?php echo lang("level_3")?></td>
            <td class="title"><?php echo lang("level_4")?></td>
            <td class="title"><?php echo lang("level_5")?></td>
            <td class="title"><?php echo lang("level_6")?></td>
            <td class="title"><?php echo lang("level_7")?></td>
          </tr>
          <tr>
            <td align="center">n/a</td>
            <td align="center">0</td>
            <td align="center">1-2</td>
            <td align="center">3-4</td>
            <td align="center">5</td>
            <td align="center">6-7</td>
            <td align="center">8-9</td>
            <td align="center">10</td>
          </tr>
          <?php }else if($mark_type == 5){?>
          <tr>
            <td class="title"><?php echo lang("level_0")?></td>
            <td class="title"><?php echo lang("level_8")?></td>
            <td class="title"><?php echo lang("level_1")?></td>
            <td class="title"><?php echo lang("level_3")?></td>
            <td class="title"><?php echo lang("level_4")?></td>
            <td class="title"><?php echo lang("level_5")?></td>
            <td class="title"><?php echo lang("level_7")?></td>
          </tr>
          <tr>
            <td align="center">n/a</td>
            <td align="center">0</td>
            <td align="center">1</td>
            <td align="center">2</td>
            <td align="center">3</td>
            <td align="center">4</td>
            <td align="center">5</td>
          </tr>
          <?php }else if($mark_type == 4){?>
          <tr>
            <td class="title"><?php echo lang("level_0")?></td>
            <td class="title"><?php echo lang("level_8")?></td>
            <td class="title"><?php echo lang("level_1")?></td>
            <td class="title"><?php echo lang("level_4")?></td>
            <td class="title"><?php echo lang("level_5")?></td>
            <td class="title"><?php echo lang("level_7")?></td>
          </tr>
          <tr>
            <td align="center">n/a</td>
            <td align="center">0</td>
            <td align="center">1</td>
            <td align="center">2</td>
            <td align="center">3</td>
            <td align="center">4</td>
          </tr>
          <?php }else if($mark_type == 2){?>
          <tr>
            <td class="title"><?php echo lang("level_0")?></td>
            <td class="title"><?php echo lang("level_8")?></td>
            <td class="title"><?php echo lang("level_1")?></td>
            <td class="title"><?php echo lang("level_7")?></td>
          </tr>
          <tr>
            <td align="center">n/a</td>
            <td align="center">0</td>
            <td align="center">1</td>
            <td align="center">2</td>
          </tr>
          <?php }?>

          </table>

         <form action="<?php echo $www_site_url?>/index.php" method="post" id="reportform">
				<input type="hidden" name="action" value="home">
				<input type="hidden" name="op" value="savereport">
				<input type="hidden" name="a_id" value="<?php echo $a_id;?>">
				<input type="hidden" name="is_saved" value="1" id="is_saved">
       <?php
		foreach ($report_questions as $k=>$v){?>
		<table width="100%" border="0" cellpadding="0" cellspacing="1" class="missionReport" style="margin-top:10px;" id="table_<?php echo $k;?>">
          <tr>
            <td colspan="3" class="title"><?php echo lang($k);?></td>
          </tr>

          <?php
            //问题序号
		  	$question_num = 0;

			foreach ($v as $kk=>$vv){
				if($vv['rq_type'] != 5) $question_num++;
				if($vv['rq_type']==2 || $vv['rq_type']==4 || $vv['rq_type']==1){
				?>
          <tr>
			 <td width="5%"><?php echo $GLOBALS['gGroupsCap'][$k]. "".($question_num)?></td>
            <td width="60%"><?php echo splitx($vv['rq_question']);?> <span id="span_ch_<?php echo $vv['rq_id'];?>" style="float:right;"></span></td>
            <td  width="35%" align="center">
             <?php if($vv['rq_type']==2){?>
            	<?php if($vv['is_na']==1){?> <span style="float:left;"> <img id="icon_updown_<?php echo $vv['rq_id'];?>" style="cursor:pointer;" src="<?php echo $www_site_url?>/public/images/up_down.jpg" onclick="display_comment(<?php echo $vv['rq_id'];?>);"><input type="checkbox" id="votebox_<?php echo $vv['rq_id'];?>" name="votebox_<?php echo $vv['rq_id'];?>" onclick="out_fs('yes_<?php echo $vv['rq_id'];?>_10_<?php if($assignmentinfo['a_markgrade'])echo $assignmentinfo['a_markgrade']; else echo $mark_type;?>');"  <?php if($vv['answer']=='A') echo "checked"; ?>>N/A</span><?php }?>
            					<div id="voteimg_<?php echo $vv['rq_id'];?>"></div>
								<input type="hidden" id="rq_ans_<?php echo $vv['rq_id'];?>" name="rq_ans_<?php echo $vv['rq_type']."_".$vv['rq_id'];?>" value="<?php echo $vv['answer'];?>">
								<?php if($assignmentinfo['a_markgrade']){?>
								<script>create_vote_img_question_mark(<?php echo $vv['rq_id'];?>,'<?php echo $vv['answer'];?>',<?php echo $assignmentinfo['a_markgrade'];?>);</script>
								<?php } else{?>
								<script>create_vote_img_mark(<?php echo $vv['rq_id'];?>,'<?php echo $vv['answer'];?>',<?php echo $mark_type;?>);</script>

			<?php }}else if($vv['rq_type']==1){ ?>
								 <?php if($vv['is_na']==1){?><span> <img id="icon_updown_<?php echo $vv['rq_id'];?>" style="cursor:pointer;" src="<?php echo $www_site_url?>/public/images/up_down.jpg" onclick="display_comment(<?php echo $vv['rq_id'];?>);"><input type="radio" name="rq_ans_<?php echo $vv['rq_type']."_".$vv['rq_id'];?>" value="A" <?php if($vv['answer']=='A')echo 'checked'; ?> onclick="display_comment(<?php echo $vv['rq_id'];?>);">N/A ;<span><?php }?>
								 <input type="radio" name="rq_ans_<?php echo $vv['rq_type']."_".$vv['rq_id'];?>" value="Y" <?php if($vv['answer']=='Y')echo 'checked'; ?> onclick="display_comment(<?php echo $vv['rq_id'];?>);">Yes ;</label>&nbsp;&nbsp;&nbsp;&nbsp;<label><input onclick="display_comment(<?php echo $vv['rq_id'];?>);" type="radio" name="rq_ans_<?php echo $vv['rq_type']."_".$vv['rq_id'];?>" value="N"  <?php if($vv['answer']=='N')echo 'checked'; ?>>No;</label>

			<?php }else if($vv['rq_type']==4){ ?>
								<input type="text" size="6" name="rq_ans_<?php echo $vv['rq_type']."_".$vv['rq_id'];?>" value="<?php echo $vv['answer']; ?>">	分钟
							<?php }?>
            </td>
          </tr>

          <?php if($vv['is_comment']==1){?>
          <tr <?php if(!$vv['comment']) echo 'style="display:none;"'?> id="td_comment_<?php echo $vv['rq_id'];?>">
          <td colspan="3" ><textarea style="width:100%;font-size:12px;height:32px;" rows="2" name="rq_comment_<?php echo $vv['rq_type']."_".$vv['rq_id'];?>" id="rq_comment_<?php echo $vv['rq_type']."_".$vv['rq_id'];?>"><?php echo $vv['comment'];?></textarea></td>
          </tr>
          <?php }?>
       		 <?php
				}else if($vv['rq_type']==3){
			
					if($vv['rq_group']==5){
					?>
			<tr>
			 <td width="5%" valign="top"><?php echo $GLOBALS['gGroupsCap'][$k]. "".($question_num)?></td>
			 <td width="60%"><?php echo splitx($vv['rq_question']);?></td>
            <td  width="35%" align="center"><input class="textfield" type="text" name="rq_ans_<?php echo $vv['rq_type']."_".$vv['rq_id'];?>" value="<?php echo $vv['answer']; ?>"></td>

          </tr>
          <?php }else{?>
			<tr>
			 <td width="5%" valign="top"><?php echo $GLOBALS['gGroupsCap'][$k]. "".($question_num)?></td>
             <td width="95%" colspan="2" style="padding:0">

		            <table width="100%" border="0" cellpadding="0" cellspacing="0">
			            <tr>
			            	<td width="50%" style="background-color:#ccc;"> <?php echo splitx($vv['rq_question'])?></td>

			          	</tr>
			           <tr>
				           <td style="height:50px">
													<textarea  style="width:100%;font-size:12px;height:60px;" name="rq_ans_<?php echo $vv['rq_type']."_".$vv['rq_id'];?>"><?php echo $vv['answer']; ?></textarea>
				           </td>
			            </tr>
		             </table>
            </td>
          </tr>
	   <?php }

				}else if($vv['rq_type']==5){
				?>
					<tr>
             			<td width="100%" colspan="3" style="padding:0">

		           			 <table width="100%" border="0" cellpadding="0" cellspacing="0">
			         		   <tr>
			            		<td width="50%" style="background-color:#ccc;"> <?php echo splitx($vv['rq_question']);?></td>
			          			</tr>

		             		</table>
            			</td>
          			</tr>
				<?php }

			}
			?>
			<?php if($v){ ?>
			<tr>
				<td align="center" colspan="3"><input type="submit" value="保存" class="btn" onclick="return checktable(document.getElementById('table_<?php echo $k;?>'));"/></td>
			</tr>
			<?php } ?>

        </table>

 		<?php }?>
 		<table width="100%" height="50">
	 		<tr>
				<td align="center"><input type="submit" value="<?php echo lang('submit')?>" class="btn" onclick="return checkform(document.getElementById('reportform'));" /></td>
			</tr>
		</table>
		</form>

		<script type="text/javascript">
		alert("为保证您的问卷内容不被丢失，请在一小时内填写完问卷并提交！");
		</script>




  <?php 	}

		}elseif($is_submitted==3){
			echo ' <p>&nbsp;</p> <div align="center">'.lang('finish_report')."</div>";
		}elseif($is_submitted==1){
			echo ' <p>&nbsp;</p> <div align="center">'.lang('approval_pass')."</div>";
		}
	}else{?>
   <p>&nbsp;</p>
   <p>&nbsp;</p>
   <p>&nbsp;</p>
   <div align="center"><?php echo lang("apply_second")?></div>
  <?php }?>

  </div>
</div>
<?php include_once("footer.html")?>
